FROM python:3.10

# 安装必要的软件包和依赖项
ENV DEBIAN_FRONTEND=noninteractive
ENV TZ=Asia/Shanghai
ENV QT_QPA_PLATFORM_PLUGIN_PATH=/usr/local/lib/python3.10/site-packages/cv2/qt/plugins

RUN ln -sf /usr/share/zoneinfo/$TZ /etc/localtime && \
    apt-get update && \
    apt-get install -y --no-install-recommends \
    openssh-server \
    xauth \
    xorg \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*

# 创建 SSH 所需的目录
RUN mkdir /run/sshd

# 设置 SSH 服务器配置
RUN sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config && \
    sed -i 's/#X11Forwarding no/X11Forwarding yes/' /etc/ssh/sshd_config

# 添加用户并设置密码
RUN useradd -m user && \
    echo "user:password" | chpasswd

# 配置 SSH 登录环境变量
ENV NOTVISIBLE "in users profile"
RUN echo "export VISIBLE=now" >> /etc/profile && \
    echo "export DISPLAY=:0" >> /etc/profile

# 设置工作目录
WORKDIR /code/smart_watch_dog/

# 安装 Python 依赖项
ADD requirements.txt requirements.txt
RUN pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple && \
    pip config set install.trusted-host mirrors.aliyun.com && \
    pip install --upgrade pip && \
    pip install -Ur requirements.txt && \
    pip cache purge

# 添加项目代码
ADD . .

# 暴露 SSH 端口
EXPOSE 22

# 启动 SSH 服务器和你的 Python 应用程序
CMD ["/usr/sbin/sshd", "-D"]